package jp.co.lkg.springsmp.services.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import jp.co.lkg.springsmp.common.Page;
import jp.co.lkg.springsmp.common.dao.GoodinfoDao;
import jp.co.lkg.springsmp.common.db.dto.GoodinfoDto;
import jp.co.lkg.springsmp.services.GoodinfoService;


@Component
public class GoodinfoServiceImpl implements GoodinfoService {

	
	
	@Autowired
    private GoodinfoDao goodinfoDao;

	@Override
	public GoodinfoDto selectByPk(GoodinfoDto dto) {
		
		return goodinfoDao.selectByPk(dto);
	}

	@Override
	public List<GoodinfoDto> select(GoodinfoDto dto) {
		// TODO Auto-generated method stub
		return goodinfoDao.select(dto);
	}

	@Override
	public void insert(GoodinfoDto dto) {
		goodinfoDao.insert(dto);
		
	}

	@Override
	public void updateByPk(GoodinfoDto dto) {
		// TODO Auto-generated method stub
		goodinfoDao.updateByPk(dto);
		
	}

	@Override
	public void deleteByPk(GoodinfoDto dto) {
		// TODO Auto-generated method stub
		goodinfoDao.deleteByPk(dto);
		
	}

	@Override
	public void updateIncludeNull(GoodinfoDto dto) {
		// TODO Auto-generated method stub
		goodinfoDao.updateIncludeNull(dto);
		
	}

	@Override
	public Page selectPage(Integer currPage, GoodinfoDto dto) {
		// TODO Auto-generated method stub
		if (dto.getGoodType()==null||dto.getGoodType().equals("0")) {
			Page page =new Page();
			if(currPage==null) currPage=1;
			page.setCurrPage(currPage);
			int Count =goodinfoDao.selectAllPage();
			page.setTotalSize(Count);
			page.initTotalPage();
			page.setMinnumber(currPage);
			page.setMaxnumber(currPage);
			dto.setMaxnumber(page.getMaxnumber());
			dto.setMinnumber(page.getMinnumber());
			page.setDatalist(goodinfoDao.selectAllGood(dto));
			return page;
		}else {
			Page page =new Page();
			if(currPage==null) currPage=1;
			page.setCurrPage(currPage);
			int Count =goodinfoDao.selectPage(dto);
			page.setTotalSize(Count);
			page.initTotalPage();
			page.setMinnumber(currPage);
			page.setMaxnumber(currPage);
			dto.setMaxnumber(page.getMaxnumber());
			dto.setMinnumber(page.getMinnumber());
			page.setDatalist(goodinfoDao.selectByType(dto));
			return page;
		}
		
		
	}

	@Override
	public List<GoodinfoDto> selectAllGood(GoodinfoDto dto) {
		// TODO Auto-generated method stub
		return goodinfoDao.selectAllGood(dto);
	}

	@Override
	public List<GoodinfoDto> selectByType(GoodinfoDto dto) {
		// TODO Auto-generated method stub
		return goodinfoDao.selectByType(dto);
	}

	@Override
	public GoodinfoDto selectByName(String goodName) {
		// TODO Auto-generated method stub
		return goodinfoDao.selectByName(goodName);
	}

	

	

	

	

}
